let request = require('../../utils/request.js')
Page({
  data: {
    list:[
      {'id': '1','name':'01','usable':true, 'broken': false, 'className': "className1"},
      {'id': '2','name':'02','usable':true, 'broken': false, 'className': "className1"},
      {'id': '3','name':'03','usable':true, 'broken': false, 'className': "className1"},
      {'id': '4','name':'04','usable':true, 'broken': false, 'className': "className1"},
      {'id': '5','name':'05','usable':true, 'broken': false, 'className': "className1"},
      {'id': '6','name':'06','usable':true, 'broken': false, 'className': "className1"},
      {'id': '7','name':'07','usable':true, 'broken': false, 'className': "className1"},
      {'id': '8','name':'08','usable':true, 'broken': false, 'className': "className1"},
      {'id': '9','name':'09','usable':true, 'broken': false, 'className': "className1"},
      {'id': '10','name':'10','usable':true, 'broken': false, 'className': "className1"}
    ],
    pInfolist: [//按功率充电套餐
      { 'id': 1, 'price': 1 },
      { 'id': 2, 'price': 2 },
      { 'id': 3, 'price': 3 },
      { 'id': 4, 'price': 4 }
    ],
    sn: null,
    num:null,
    detail:'',
    postlist:{},
    select:[-1,-1],
    second:'获取验证码',
    sign:false,//控制用户点击发送请求
    frequency:0,//用户点击立即支付次数
    showd: false,
    active_showd: true,
    show: false,
    loadData:null,
    pocketlist: null,
    selectDiscount:[],
    discountlist: [],//优惠券列表
    activityId: null,//活动id
    typeId: '',//（1：折现金券；0：折扣券）
    discountId: '', //支付传值
    discountName: '', //支付传值
    discount_name: null,//页面显示
    discount_val: null,
    radioChangeVal: null,
    money: null,
    radio: [
      { value: "0", checked: false, disabled: false },//月卡
      { value: "1", checked: false, disabled: false },//支付宝
      { value: "2", checked: false, disabled: false }//钱包
    ],
    charge_cardlist: null,
    postcardlist: {},//月卡,余额支付
  },
  choose (e) {
    if (this.data.list[e.currentTarget.dataset.index]['usable']&&!this.data.list[e.currentTarget.dataset.index]['broken']) {
      this.data.select[0]=e.currentTarget.dataset.index
      this.data.postlist['charge_mouth']=this.data.list[e.currentTarget.dataset.index]['id']
      this.setData({
        select:this.data.select,
      })
    }
  },
  choosetime(e){
    if (this.data.detail['info']) {//按小时充电
      this.data.postlist['charge_time'] = this.data.detail['info'][e.currentTarget.dataset.index]['hours'] * 60 * 60
      this.data.postlist['cash'] = parseFloat(this.data.detail['info'][e.currentTarget.dataset.index]['price']).toFixed(2)
    } else if (this.data.detail['pInfo']) {//按功率充电
      this.data.postlist['cash'] = parseFloat(this.data.pInfolist[e.currentTarget.dataset.index]['price']).toFixed(2)
    }
    this.data.select[1]=e.currentTarget.dataset.index
     if (this.data.radioChangeVal === null) {
      this.radioDisable();
      this.radioDefault();
      this.setData({
        radio: this.data.radio
      })
    }
    this.initMoney();
    this.setData({
      select: this.data.select,
      postlist: this.data.postlist,
      show: true,
      radioChangeVal: this.data.radioChangeVal,
      money: this.data.money,
    })
    // this.setData({
    //   select:this.data.select,
    //   postlist:this.data.postlist
    // })
  },
  pickertime(e){
    this.data.postlist['charge_time']=this.data.detail['info'][e.detail.value]['hours']*60*60
    // this.data.postlist['total']=(this.data.detail['info'][e.detail.value]['hours']*this.data.detail['info'][e.detail.value]['price']).toFixed(2)
    this.data.postlist['cash']=parseFloat(this.data.detail['info'][e.detail.value]['price']).toFixed(2)
    this.data.postlist['money']=this.data.postlist['cash']*100
    this.data.select[1]=e.detail.value
    this.setData({
      select:this.data.select,
      postlist:this.data.postlist
    })
  },
  check(){
    if (!this.data.postlist.charge_time  && !this.data.postlist.cash) {
      my.showToast({
        content:'选择充电套餐',
        type:'fail',
        duration: 1000
      })
      return false
    } else if (!this.data.postlist.charge_mouth) {
      my.showToast({
        content:'选择充电口',
        type:'fail',
        duration: 1000
      })
      return false
    }
    return true
  },
   //获取页面支付方式数据
  getuserinfo() {
    let success = (res) => {
      if (res.pocket) {//钱包
        this.setData({
          pocketlist: res.pocket,
        })
      }
      if (res.charge_card) {//月卡
        this.data.postcardlist.card_id = res.charge_card.id;
        this.data.postcardlist.source = 1;
        res.charge_card.remaintime = (parseInt(res.charge_card.remain_time) / 3600).toFixed(1)
        this.setData({
          charge_cardlist: res.charge_card,
          postcardlist: this.data.postcardlist,
        })
      }
      if (res.discounts) {//优惠券
        this.setData({
          discountlist: res.discounts
        })
      }
      if (this.data.radioChangeVal != null) {
        this.radioDisable();
        this.radioDefault();
        this.setData({
          radio: this.data.radio
        })
      }
      setTimeout(()=> {
        my.hideLoading();
      }, 2000) 
    }
    let fail = (res) => {
      setTimeout(()=> {
        my.hideLoading();
      }, 2000) 
      if(res.error==12||res.error==19){
        my.confirm({
          title: '温馨提示',
          content: '网络错误，请核实是否有网',
          confirmButtonText: '重新加载',
          cancelButtonText: '暂不需要',
          success: (result) => {
            if(result.confirm === true){
              this.getuserinfo()
            }else{
              my.switchTab({
                url: 'index'
              });
            }
          },
        });
      }else if(res.error==13){
        my.confirm({
          title: '温馨提示',
          content: '获取用户信息超时，请重试',
          confirmButtonText: '重新加载',
          cancelButtonText: '暂不需要',
          success: (result) => {
            if(result.confirm === true){
              this.getuserinfo()
            }else{
              my.switchTab({
                url: 'index'
              });
            }
          },
        });
      }else{
        my.showToast({
          content: '网络异常，请检查网络',
          type: "fail",
          duration: 3000
        })
        my.switchTab({
          url: 'index'
        });
      }
    }
    request.getdata("/users/user/show", {}, success, this, fail);
  },
  //设置默认选中
  radioDefault() {
    if (this.data.charge_cardlist && this.data.postlist.charge_time <= parseInt(this.data.charge_cardlist.remainTime)*3600 && this.data.discountId === null) {//判断月卡否存在,余额是否充足
      this.data.radioChangeVal = this.data.radio[0].value;
      this.data.radio[0].checked = true;
      this.data.radio[1].checked = false;
      this.data.radio[2].checked = false;
    } else if (this.data.pocketlist && parseFloat(this.data.postlist.cash) <= parseFloat(this.data.pocketlist.balance)) {//判断钱包是否存在，余额是发充足
      this.data.radioChangeVal = this.data.radio[2].value;
      this.data.radio[2].checked = true;
      this.data.radio[1].checked = false;
      this.data.radio[0].checked = false;
    } else {
      this.data.radioChangeVal = this.data.radio[1].value;
      this.data.radio[1].checked = true;
      this.data.radio[0].checked = false;
      this.data.radio[2].checked = false;
    }
    this.data.radio = this.data.radio.slice()
  },
  //计算用户需要支付总金额
  initMoney() {
    if (this.data.radioChangeVal && this.data.postlist.cash) {
      if (this.data.radioChangeVal === "0") {
        this.data.money = "0.00"
        my.removeStorage({//清除选择优惠券的缓存
          key: 'selectDiscount',
          success:(res)=> {
          }
        })
        this.setData({
          discount_val: null,
          discount_name: null
        })
      } else {
        if (this.data.typeId == 0) {//折扣券
          this.data.money = (parseFloat(this.data.postlist.cash) * this.data.discount_val).toFixed(2);
        } else if (this.data.typeId == 1) {//现金券
          this.data.money = (this.data.postlist.cash) - this.data.discount_val;
        } else {//没有折扣
          this.data.money = parseFloat(this.data.postlist.cash).toFixed(2)
        }
      }
    }

  },
  //设置禁用
  radioDisable() {
    if (!this.data.charge_cardlist || this.data.postlist.charge_time > parseInt(this.data.charge_cardlist.remainTime)*3600) {//判断月卡否存在,余额是否充足
      this.data.radio[0].disabled = true;
    } else {
      this.data.radio[0].disabled = false;
    }
    if (!this.data.pocketlist || parseFloat(this.data.postlist.cash) > parseFloat(this.data.pocketlist.balance)) {//判断钱包是否存在，余额是否充足
      this.data.radio[2].disabled = true;
    } else {
      this.data.radio[2].disabled = false;

    }
  },
  //禁用后弹出框
  disablePopupCard(){
    if (!this.data.charge_cardlist ) {//判断月卡否存在
      my.confirm({
        title: '温馨提示',
        content: '还没有月卡哦!',
        confirmButtonText: '马上购买',
        cancelButtonText: '暂不需要',
        success: (result) => {
          if(result.confirm){
            my.navigateTo({
              url: '/pages/myWallet/renew'
            })
          }else if (result.cancel) {
            // console.log('用户点击取消')
          }
        },
      });
    };
  },
  disablePopupWallet(){
    if (!this.data.pocketlist) {//判断钱包是否存在，余额是否充足
      my.confirm({
        title: '温馨提示',
        content: '钱包空了呢!',
        confirmButtonText: '马上充值',
        cancelButtonText: '暂不需要',
        success: (result) => {
          if(result.confirm){
            my.navigateTo({
              url: '/pages/myWallet/recharge'
            })
          }else if (result.cancel) {
            // console.log('用户点击取消')
          }
        },
      });
    }
    if(this.data.pocketlist&&(parseFloat(this.data.postlist.cash) > parseFloat(this.data.pocketlist.balance))){
      my.confirm({
        title: '温馨提示',
        content: '钱包余额不足!',
        confirmButtonText: '马上充值',
        cancelButtonText: '暂不需要',
        success: (result) => {
          if(result.confirm){
            my.navigateTo({
              url: '/pages/myWallet/recharge'
            })
          }else if (result.cancel) {
            // console.log('用户点击取消')
          }
        },
      });
    }
  },
 //返回order页面
  backorder(){
    my.getStorage({//获取选择优惠券缓存信息
      key: 'selectDiscount',
      success: (res) => {
        this.data.selectDiscount = res.data
        if (res.data) {
          this.data.discountId = res.data.id;
          this.data.activityId = res.data.activityId;          
          this.data.discountName = res.data.name;
          this.data.discount_name = res.data.discount;
          this.data.discount_val = res.data.value;
          this.data.typeId = res.data.typeId
          if (this.data.postlist.charge_time && this.data.postlist.cash) {
            this.radioDisable()
            if (this.data.radioChangeVal !== "1") {
              this.radioDefault();//默认选中
            }
          }
          this.initMoney();
          //此处如果直接设置 this.setData this.data.radio  页面不会更新
          let radio = this.data.radio;
          this.setData({
            discount_name: this.data.discount_name,
            radio: null,
            money: this.data.money,
            radioChangeVal:this.data.radioChangeVal
          })
          //先让 this.data.radio为null  然后再 this.setData this.data.radio 来强制初始化数据
          setTimeout(()=>{
            this.setData({
              radio: radio
            })
          })
        } else {//res可能为空或undefined
          this.data.discountId = null;
          this.data.discountName = null;
          this.data.activityId = null;      
          this.data.discount_name = null;
          this.data.discount_val = null;
          this.data.typeId = null
          if (this.data.postlist.charge_time && this.data.postlist.cash) {
            this.radioDisable()
            // if (this.data.radioChangeVal !== "1") {
            //   this.radioDefault();//默认选中
            // }
          }
          this.initMoney();
          let radio = this.data.radio;
          this.setData({
            discount_name: this.data.discount_name,
            radio: this.data.radio,
            radioChangeVal: this.data.radioChangeVal,
            money: this.data.money,
          })
          //先让 this.data.radio为null  然后再 this.setData this.data.radio 来强制初始化数据
          setTimeout(()=>{
            this.setData({
              radio: radio
            })
          })          
        }
      }, fail: () => {
        this.data.discountId = null;
        this.data.discountName = null;
        this.data.activityId = null; 
        this.data.discount_name = null;
        this.data.discount_val = null;
        this.data.typeId = null;
        if (this.data.postlist.charge_time && this.data.postlist.cash) {
          this.radioDisable()
          // if (this.data.radioChangeVal !== "1") {
          //   this.radioDefault();//默认选中
          // }
        }
        this.initMoney();
        let radio = this.data.radio;
        this.setData({
          discount_name: this.data.discount_name,
          radio: this.data.radio,
          radioChangeVal: this.data.radioChangeVal,
          money: this.data.money,
        })
        //先让 this.data.radio为null  然后再 this.setData this.data.radio 来强制初始化数据
        setTimeout(()=>{
          this.setData({
            radio: radio
          })
        })   
      }
    });
  },
  // 支付方式选择
  radioChange(e) {
    this.data.radioChangeVal = e.detail.value;
    this.initRadio();
    this.initMoney();
    this.setData({
      radioChangeVal: this.data.radioChangeVal,
      money: this.data.money
    });
  },
  //处要用来同步radioChangeVal和radio
  initRadio(){
    if (this.data.radioChangeVal === "0"){
      this.data.radio[0].checked = true;
      this.data.radio[1].checked = false;
      this.data.radio[2].checked = false;
    } else if (this.data.radioChangeVal === "1"){
      this.data.radio[0].checked = false;
      this.data.radio[1].checked = true;
      this.data.radio[2].checked = false;
    } else if (this.data.radioChangeVal === "2") {
      this.data.radio[0].checked = false;
      this.data.radio[1].checked = false;
      this.data.radio[2].checked = true;
    }
  },
  //立即支付
  checkMobile() {
    if (this.data.sign == true) {
      my.showToast({
          content: '请勿重复点击',
          type: "fail",
          duration: 1000
        })
      return
    }else{
      this.data.sign = true;
    }
    if (!this.check()) {
      this.data.sign = false
      return false;
    } else {
      // if (this.data.sign==true){
        my.showLoading({
          content: '加载中...'
        });
        if (this.data.radioChangeVal === "1") {
          this.pay()
        } else {
          this.paycard();
        }
        // this.data.sign = false;
        // setTimeout(() => {
        //   this.data.sign = true
        // }, 10000)
      // }else{
      //   if (this.data.frequency>=3){
      //     my.showToast({
      //       content: '支付频繁，请10s后操作',
      //       type:'fail',
      //     })
      //     this.data.frequency=0
      //   }
      // }
      // this.data.frequency++
    }
  },
  pay(){
    if (this.check()) {
      this.data.sign = false
      this.data.postlist.power = 0;
      this.data.postlist.chargeMethod = this.data.detail.chargeMethod;
      this.data.postlist.source = 1;
      this.data.postlist.discountId = this.data.discountId;    
      this.data.postlist.actualMoney = Number(this.data.money);//实际付款金额
      if (this.data.postlist.actualMoney===0){
        my.showToast({
          content: '支付金额为0，无法使用支付宝支付',
          type: 'fail',
          duration: 1000
        })
        this.data.sign = false
        return
      }
      this.data.postlist.cash = Number(this.data.postlist.cash);//套餐价格
      this.data.postlist.discountCash = this.data.postlist.cash - this.data.postlist.actualMoney//优惠券金额
      this.data.postlist.discountName = this.data.discountName;  
      this.data.postlist.activityId = this.data.activityId;      
      let success=(param)=>{
          my.tradePay({
          orderStr: param.callback, 
          success: (res) => {
            setTimeout(()=> {
              my.hideLoading();
            }, 2000) 
            if (res.resultCode==9000) {
              my.redirectTo({
                url:'/pages/home/state?num='+param.num
              })
              my.showToast({
                content:'支付成功',
                type:'success',
                duration: 1000
              })
            }
          },
          fail: (res) => {
            setTimeout(()=> {
              my.hideLoading();
            }, 2000) 
          }
          });
        // }
      }
      let fail=(res)=>{
            if(res.error==12||res.error==19){
              my.confirm({
                title: '温馨提示',
                content: '网络错误，请核实是否有网',
                confirmButtonText: '重新加载',
                cancelButtonText: '暂不需要',
                success: (result) => {
                  if(result.confirm === true){
                    this.pay()
                  }else{
                    my.switchTab({
                      url: 'index'
                    });
                  }
                },
              });
            }else if(res.error==13){
              my.confirm({
                title: '温馨提示',
                content: '支付超时，请重试',
                confirmButtonText: '重新加载',
                cancelButtonText: '暂不需要',
                success: (result) => {
                  if(result.confirm === true){
                    this.pay()
                  }else{
                    my.switchTab({
                      url: 'index'
                    });
                  }
                },
              });
            }else{
              my.showToast({
                content: '网络异常，请检查网络',
                type: "fail",
                duration: 3000
              })
              my.switchTab({
                url: 'index'
              });
            }
          }
      request.postdata('/Pay/alipay',this.data.postlist,success,this, fail)
    }
  },
  paycard(){
    if (this.check()) {
      this.data.sign = false
      const res = my.getStorageSync({ key: 'locationlist' });
      if(res){
        this.data.postcardlist.area_id = res.data.area_id;
        this.data.postcardlist.sn = this.data.postlist.sn;
        this.data.postcardlist.source = 1;
        this.data.postcardlist.power = 0;
        this.data.postcardlist.chargeMethod = this.data.detail.chargeMethod;
        this.data.postcardlist.discountId = this.data.discountId;
        this.data.postcardlist.discountName = this.data.discountName;
        this.data.postcardlist.activityId = this.data.activityId;              
        this.data.postcardlist.cash = Number(parseFloat(this.data.postlist.cash).toFixed(2));//套餐价格
        this.data.postcardlist.actualMoney = Number(this.data.money);//实际付款金额
        this.data.postcardlist.discountCash = this.data.postcardlist.cash - this.data.postcardlist.actualMoney//优惠券金额
        this.data.postcardlist.charge_time = this.data.postlist.charge_time;
        this.data.postcardlist.charge_mouth = parseInt(this.data.postlist.charge_mouth);
        let success=(param)=>{
          if (param.num) {
            setTimeout(()=> {
              my.redirectTo({
                url: '/pages/home/state?num='+param.num
              })
            }, 2000)            
            my.showToast({
              content:'支付成功',
              type:'success',
              duration: 1000
            })
            setTimeout(()=> {
              my.hideLoading();
            }, 2000) 
          }else{
              my.showToast({
              content:'支付失败',
              type:'fail',
              duration: 1000
            })
            setTimeout(()=> {
              my.hideLoading();
            }, 1000) 
          }
        }
        let fail=(res)=>{
          if(res.error==12||res.error==19){
            my.confirm({
              title: '温馨提示',
              content: '网络错误，请核实是否有网',
              confirmButtonText: '重新加载',
              cancelButtonText: '暂不需要',
              success: (result) => {
                if(result.confirm === true){
                  this.paycard()
                }else{
                  my.switchTab({
                    url: 'index'
                  });
                }
              },
            });
          }else if(res.error==13){
            my.confirm({
              title: '温馨提示',
              content: '支付超时，请重试',
              confirmButtonText: '重新加载',
              cancelButtonText: '暂不需要',
              success: (result) => {
                if(result.confirm === true){
                  this.paycard()
                }else{
                  my.switchTab({
                    url: 'index'
                  });
                }
              },
            });
          }else{
            my.showToast({
              content: '网络异常，请检查网络',
              type: "fail",
              duration: 3000
            })
            my.switchTab({
              url: 'index'
            });
          }
        }
        if (this.data.radioChangeVal === "0") {//月卡支付
          request.postdata('/pay/charge_card', this.data.postcardlist, success, this, fail)
        } else if (this.data.radioChangeVal === "2") {//钱包支付
          request.postdata('/pay/pocket', this.data.postcardlist, success, this, fail)
        }
      }else{
        my.showToast({
          content: '获取location失败',
          type: "fail",
          duration: 3000
        })
        setTimeout(()=> {
          my.hideLoading();
        }, 2000) 
        my.switchTab({
          url: 'index'
        });
      }
    }
  },
  getSn(data) {
    if (data) {
      this.data.detail = data
    } else {
      data = this.data.detail
    }
    this.getFacilityInfo(data);
  },
  getFacilityInfo(data) {
    let success = (data)=> {
      if (data) {
        if (data['info']){
          for (let i = data['info'].length - 1; i >= 0; i--) {
            data['info'][i]['info'] = data['info'][i]['price'] + "元/" + data['info'][i]['hours'] + "小时"
          }
        }
        this.data.select = [-1, -1];
        this.data.radioChangeVal = null;
        this.data.postlist = {};
        if (data['chargemouth']) {
          //初始化数据
          for(let i=0;i<this.data.list.length;i++){
            this.data.list[i]['usable']=true;
          };
          data['chargemouth'].forEach((value,index,array)=>{
            this.data.list[value-1]['usable'] = false;
            if (!this.data.list[value - 1]['usable']) {
              this.data.list[value - 1]['className'] = 'className2'
            }
          });
        }
        if (data['brokenmouth']) {
          //初始化数据
          for(let i=0;i<this.data.list.length;i++){
            this.data.list[i]['broken']=false;
          };
          data['brokenmouth'].forEach((value,index,array)=>{
            this.data.list[value - 1]['broken'] = true
            if (this.data.list[value - 1]['broken']){
              this.data.list[value - 1]['className'] = 'className3'
            }
          });
        }
        this.setData({
          list:this.data.list,
          detail:data,
          select: this.data.select,
          postlist:this.data.postlist,
          pInfolist: this.data.pInfolist
        })
        this.data.postlist['sn']=data['sn']
      } else{
        my.showToast({
          content:'该设备不存在',
          type:'fail',
          duration: 1000
        })
        my.switchTab({
          url: 'index'
        });
      }
      this.getuserinfo();
    }
    let fail = (res) => {
      setTimeout(()=> {
        my.hideLoading();
      }, 2000) 
      if(res.error==12||res.error==19){
        my.confirm({
          title: '温馨提示',
          content: '网络错误，请核实是否有网',
          confirmButtonText: '重新加载',
          cancelButtonText: '暂不需要',
          success: (result) => {
            if(result.confirm === true){
              this.getFacilityInfo(data)
            }else{
              my.switchTab({
                url: 'index'
              });
            }
          },
        });
      }else if(res.error==13){
        my.confirm({
          title: '温馨提示',
          content: '获取设备信息超时，请重试',
          confirmButtonText: '重新加载',
          cancelButtonText: '暂不需要',
          success: (result) => {
            if(result.confirm === true){
              this.getFacilityInfo(data)
            }else{
              my.switchTab({
                url: 'index'
              });
            }
          },
        });
      }else{
        my.showToast({
          content: '网络异常，请检查网络',
          type: "fail",
          duration: 3000
        })
        setTimeout(() => {
          my.switchTab({
            url: 'index'
          });
        }, 2000);
      }
    }
    request.postdata('/Index/getFacilityInfo', { 'sn': data }, success, this, fail)
    
  },
  getLocation: function() {
    my.getLocation({
      type: 1,
      success: (res) => {
        my.setStorageSync({
          key: 'locationlist',
          data: {
            province: res.province,
            area_id: res.districtAdcode,
            city: res.city,
          }
        });
      },
      fail: function() {
      }
    })
  },
  onLoad(data) {
    this.data.loadData = data;
  },
  onShow() {
    this.backorder()
    if(this.data.isBack){
      return;
    }
    my.getNetworkType({
      success: (res) => {
        if(!res.networkAvailable||res.networkType=='UNKNOWN'){
          my.showToast({
            content: '网络状态不佳，请检查网络',
            type:'fail',
            duration: 2000
          })
        }
      }
    })
    this.getLocation()
    if (!this.data.loadData){
      my.switchTab({
        url: 'index'
      });
      my.showToast({
        content: '未获取到设备,请重新操作!',
        type:'fail',
        duration: 3000
      })
      return
    }
    my.showLoading({
      content: '加载中...'
    });
    if (!!this.data.loadData && this.data.loadData.q) {
      this.data.sn = this.data.loadData.q.substr(this.data.loadData.q.length - 8, 8)
    } else {
      this.data.sn = this.data.loadData.sn
    }
    this.getSn(this.data.sn)
  },
  onUnload(res) {
    my.removeStorage({
      key: 'selectDiscount',
      success: ()=> { }
    })
  },
  // 活动弹出框
  active_click() {
    this.setData({
      active_showd: !this.data.active_showd
    })
  },
  // 到钱包充值
  to_wallet_charge() {
    my.navigateTo({
      url: '/pages/myWallet/recharge'
    });
  },
 coupon_show() {
    my.navigateTo({
      url: 'coupon'
    });

  },
// /**
//  * 弹出层
//  */
//   powerDrawer: function (typename) {
//     if(typename == 'open'){
//       var currentStatu = typename;      
//     }else{
//       var currentStatu = 'close';      
//     }
//     this.util(currentStatu)
//   },
//   util: function (currentStatu) {
//     /* 动画部分 */
//     // 第1步：创建动画实例 
//     var animation = my.createAnimation({
//       duration: 200, //动画时长 
//       timingFunction: "linear", //线性 
//       delay: 0 //0则不延迟 
//     });

//     // 第2步：这个动画实例赋给当前的动画实例 
//     this.animation = animation;

//     // 第3步：执行第一组动画 
//     animation.opacity(0).rotateX(-100).step();

//     // 第4步：导出动画对象赋给数据对象储存 
//     this.setData({
//       animationData: animation.export()
//     })
//     var that = this;
//     // 第5步：设置定时器到指定时候后，执行第二组动画 
//     setTimeout(function () {
//       // 执行第二组动画 
//       animation.opacity(1).rotateX(0).step();
//       // // 给数据对象储存的第一组动画，更替为执行完第二组动画的动画对象 
//       that.setData({
//         animationData:animation.export()
//       })

//       //关闭 
//       if (currentStatu == "close") {
//         this.setData(
//           {
//             showModalStatus: false
//           }
//         );
//       }
//     }.bind(this), 200)

//     // 显示 
//     if (currentStatu == "open") {
//       this.setData(
//         {
//           showModalStatus: true
//         }
//       );
//     }
//   } 
})
